<?php

namespace App\Tables;


class Admin extends User
{
    /**
     * passport API后台用户登录认证字段
     * @param $username
     * @return mixed
     */
    public function findForPassport($username)
    {
        $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
        $column_name = preg_match($pattern, $username) ? 'email' : 'name';

        return $this->where($column_name, $username)->backend()->first();
    }
}
